$(function () {
    let markid = getUrlString('markid');
    let id = getUrlString('id');
    let name = decodeURIComponent(getUrlString('name'));
    let phone = decodeURIComponent(getUrlString('phone'));
    let adress = decodeURIComponent(getUrlString('adress'));


    $('#name').val(name);
    $('#phone').val(phone);
    $('#addressDetail').val(adress);

    $('#delete').click(function () {
        getData('post','/niu/apiv3/fahuo_address_del.php',{'markid':markid,'adid':id},function (data) {
            console.log(data);
            laymsg('地址删除成功');
            setTimeout(function () {
                nativeCommand("dancool://activity=reflashfin")
            },500)
        })
    });

    $('#orderBtn').click(function () {
        let name = $('#name').val();
        let phone = $('#phone').val();
        let addressDetail = $('#addressDetail').val();
        let options1 = $("#local1 option:selected").attr('data-code'); //获取选中的项
        let options2 = $("#local2 option:selected").attr('data-code'); //获取选中的项
        let options3 = $("#local3 option:selected").attr('data-code'); //获取选中的项
        if (name === ''){
            laymsg('请输入姓名');
            return
        }
        if (!phoneNumberVer(phone)){
            return;
        }

        if (addressDetail === ''){
            laymsg('请输入详细地址');
            return
        }

        let data = {
            'markid':markid,
            'type':1,
            'phone':phone,
            'address':addressDetail,
            'adid':id,
            'remark':'update',
            'local1':options1,
            'local2':options2,
            'local3':options3,
            'name':name,
        };

        getData('post','/niu/apiv3/fahuo_address_add.php',data,function (data) {
            console.log(data);
            laymsg('更新地址成功');
            setTimeout(function () {
                nativeCommand("dancool://activity=reflashfin")
            },500)
        })
    })
});